package com.zzh.lib.views.adapter;

import com.zzh.lib.views.def.IExpandMoreCallback;

/**
 * Created by ZZH on 2022/6/1.
 *
 * @Date: 2022/6/1
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description: 可折叠的ListView
 */
public abstract class HExpandMoreAdapter<T> extends HBaseAdapter<T> implements IExpandMoreCallback {
    private final int maxItem;
    private boolean flagExpandMore = false;

    public HExpandMoreAdapter(int maxItem) {
        super();
        if (maxItem < 0) {
            maxItem = 0;
        }
        this.maxItem = maxItem;
    }

    @Override
    public int getCount() {
        if (flagExpandMore) {
            int count = mData == null ? 0 : mData.size();
            count = count > maxItem ? maxItem : count;
            return count;
        } else {
            return mData == null ? 0 : mData.size();
        }
    }


    @Override
    public void expandMore(boolean flag) {
        flagExpandMore = flag;
    }

    public boolean isExpandMore() {
        return flagExpandMore;
    }

    @Override
    public int getMaxItem() {
        return maxItem;
    }

    @Override
    public int getRealCount() {
        return mData.size();
    }
}
